package com.uhealin;

import java.io.IOException;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

public class TotalSaleReducer extends TableReducer<Text,DoubleWritable,ImmutableBytesWritable> {

	public void reduce(Text key, Iterable<DoubleWritable> values, Context context) throws  InterruptedException, IOException {
		double i = 0;
		for (DoubleWritable val : values) {
			i += val.get();
		}
		Put put = new Put(Bytes.toBytes(key.toString()));
		put.addImmutable(Bytes.toBytes("cf1"), Bytes.toBytes("count"), Bytes.toBytes(i));

		context.write(null, put);
	}
	
}
